package com.hmdp.rabbitmq;

import com.hmdp.entity.VoucherOrder;
import com.hmdp.mapper.VoucherOrderMapper;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class OrderConsumer {
    @Autowired
    private VoucherOrderMapper voucherOrderMapper;
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "order.queue"),
            exchange = @Exchange(name = "order.exchange", type = ExchangeTypes.FANOUT)
    ))
    public void processOrder(VoucherOrder voucherOrder) {
        // 模拟订单处理（扣减库存、写入数据库等）
        voucherOrderMapper.insert(voucherOrder);

        // TODO: 实际业务逻辑（数据库操作、库存扣减等）
        System.out.println("订单创建完成！");
    }
}
